version: '3.9'

services:
    db:
        image: postgres:16.2-alpine3.19
        container_name: database
        restart: always
        volumes:
            - ./db:/docker-entrypoint-initdb.d
            - ./db/data:/var/lib/postgresql/data
        ports:
            - "6432:5432"
        env_file:
            - ./sample.env
        healthcheck:
            test: [ "CMD-SHELL", "pg_isready -U postgres" ]
            interval: 5s
            timeout: 5s
            retries: 5
    web:
        build: .
        container_name: web-application
        restart: always
        command: /usr/src/fastapi_project_template/docker-entrypoint.sh
        volumes:
            - ./src:/usr/src/fastapi_project_template/src
            - ./docker-entrypoint.sh:/usr/src/fastapi_project_template/docker-entrypoint.sh
            - ./alembic:/usr/src/fastapi_project_template/alembic
            - ./alembic.ini:/usr/src/fastapi_project_template/alembic.ini
        ports:
            - "8000:8000"
        env_file:
            - ./sample.env
        depends_on:
            db:
                condition: service_healthy